#include "game_screen.h"

#include "ai.h"

////////////////////////////////////////////////////////////////////////////////

GameScreen::GameScreen(int num_players, AI** ai)
{
  _sim_parameters.num_players = num_players;
  
  for (int i = 0; i < num_players; i++)
  {
    _sim_parameters.ai[i] = ai[i];
  }
}

bool GameScreen::create()
{
  _sim_parameters.screen_dim = Graphics_getScreenDim();
  _sim_parameters.player_colour[0] = Colour::RED;
  _sim_parameters.player_colour[1] = Colour::BLUE;
  _sim_parameters.player_colour[2] = Colour::GREEN;
  _sim_parameters.player_colour[3] = Colour::YELLOW;
  
  /*for (unsigned i = 0; i < _sim_parameters.num_players; i++)
  {
    _sim_parameters.ai[i] = NULL;
  }
  
  _sim_parameters.ai[0] = new ExampleAI();
  _sim_parameters.ai[1] = new DumbAI();
  _sim_parameters.ai[2] = new SmokeyAI();
  _sim_parameters.ai[3] = new ChrisAI();*/
  
  _simulation = new Simulation(_sim_parameters);
  
  _background = new Background();
  _background->setColour(Colour::WHITE);
  
  _viewport = new Viewport(_simulation);
  
  GUI_setBackground(_background);
  GUI_setContent(_viewport);
  
  return true;
}

void GameScreen::destroy()
{
  delete _viewport;
  delete _background;
  delete _simulation;
}

void GameScreen::update(unsigned dM, float dT)
{
  _simulation->update(dM, dT);
}

void GameScreen::handleKeyDown(const GUIKeyDownEvent* event)
{
  if (event->getKey() == KEY_ESCAPE)
  {
    quit();
  }
}

void GameScreen::handleWidgetEvent(const GUIWidgetEvent* event)
{
  
}
